<template>
  <div>
    <el-form label-width="200px" size="mini">
      <el-form-item label="平台">
        <span>{{ split.platform | preSymbol }}</span>
      </el-form-item>
      <el-form-item label="机构">
        <span>{{ split.school | preSymbol }}</span>
      </el-form-item>
      <!-- <el-form-item label="挂载机构">
        <span>{{ split.mount_school | preSymbol }}</span>
      </el-form-item> -->
      <el-form-item label="讲师">
        <span>{{ split.teacher | preSymbol }}</span>
      </el-form-item>
      <el-form-item label="分享者">
        <span>{{ split.share | preSymbol }}</span>
      </el-form-item>
      <el-form-item label="1级分销员">
        <span>{{ split.distributor_first | preSymbol }}</span>
      </el-form-item>
      <el-form-item label="2级分销员">
        <span>{{ split.distributor_second | preSymbol }}</span>
      </el-form-item>
      <el-form-item label="机构分成配置状态"><status :row="datas" /></el-form-item>
      <el-form-item v-if="datas.status == 2">
        <el-button type="primary" :disabled="disableSubmit" @click="pass">通过</el-button>
        <el-button @click="reasonBoxVisible = true">驳回</el-button>
      </el-form-item>
    </el-form>
    <el-dialog :visible.sync="reasonBoxVisible" width="32%" title="驳回原因" :close-on-click-modal="false" append-to-body>
      <edu-textarea :value.sync="reason" :args="{ maxlength: 200, word_limit: 1, rows: 4, placeholder: '输入驳回原因' }" />
      <el-row type="flex" align="middle" justify="center" class="reason-btns">
        <el-button size="small" plain @click="reasonBoxVisible = false">取消</el-button>
        <el-button size="small" type="primary" :disabled="disableSubmit" @click="reject">驳回</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import Status from './components/status.vue';
import EduTextarea from '@public/form/textarea.vue';
export default {
  components: {
    Status,
    EduTextarea
  },
  props: {
    datas: {
      type: Object,
      required: true
    }
  },
  inject: ['reload'],
  data() {
    return {
      disableSubmit: false,
      reasonBoxVisible: false,
      reason: ''
    };
  },
  computed: {
    split() {
      return this.datas ? this.datas.value : {};
    }
  },
  methods: {
    pass: function() {
      this.disableSubmit = true;
      this.$box
        .confirm('通过机构申请的分成比例', '审核确认')
        .then(() => {
          this.$http.post(
            '/school/admin/split/config/' + this.datas.id + '/examine',
            {
              status: 1
            },
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.disableSubmit = false;
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {
          this.disableSubmit = false;
        });
    },
    reject: function() {
      if (!this.reason) {
        this.$message.warning('请填写驳回原因');
        return false;
      }
      this.disableSubmit = true;
      this.$http.post(
        '/school/admin/split/config/' + this.datas.id + '/examine',
        {
          status: 0,
          reason: this.reason
        },
        response => {
          this.$message.success(response.msg, _ => {
            this.reload();
            this.reasonBoxVisible = false;
          });
        },
        error => {
          this.disableSubmit = false;
          this.$message.error(error.msg);
        }
      );
    }
  }
};
</script>

<style scoped>
.reason-btns {
  margin-top: 20px;
}
</style>
